<template>
  <div >
    <span   style="  font-weight: bold">  {{formatVolume(value)}} </span>
  </div>
</template>

<script>
export default {
  name: "TurnoverNumberColumn",
  props:{
    value: {
      type: Number ,
      default: 0
    }
  },
  methods:{
    formatVolume(value, unitName = '手') {
      const units = [
        { threshold: 1e8, suffix: '亿', divisor: 1e8 },  // 100,000,000
        { threshold: 1e4, suffix: '万', divisor: 1e4 },  // 10,000
      ];

      // 处理无效输入
      if (typeof value !== 'number' || isNaN(value)) return '-';
      if (value === 0) return `0${unitName}`;

      // 匹配单位
      let selectedUnit = units.find(unit => value >= unit.threshold) || null;
      if (!selectedUnit) {
        // 小于 1 万时直接显示千位分隔符
        return `${value.toLocaleString('zh-CN')}${unitName}`;
      }

      // 计算并格式化
      const dividedValue = value / selectedUnit.divisor;
      const isInteger = dividedValue % 1 === 0;
      const formatted = isInteger ?
          dividedValue.toFixed(0) :
          dividedValue.toFixed(1).replace(/\.0$/, '');

      return `${formatted}${selectedUnit.suffix}${unitName}`;
    }
  }
}
</script>

<style scoped>

</style>
